#!/bin/sh

program=$1
program_dir=$(dirname $0)

# Prefer to OOM kill job runner first.
# This prevents some server/client test cases from blocking on OOM.
echo 1000 > /proc/$PPID/oom_score_adj

echo $$ >> $TMP/pid-tests

shift

fifo=$TMP/fifo-$program
[ -p "$fifo"  ] || mkfifo $fifo
[ -L "$SRC/bin/tee-$program"  ] || ln -s -T /usr/bin/tee $SRC/bin/tee-$program
tee-$program -a $TMP_RESULT_ROOT/$program < $fifo &
echo $! >> $TMP/.pid-pipes
exec /usr/bin/time -v -o $TMP/${program}.time $exec_prefix $program_dir/$program "$@" > $fifo
